---
title: Tools
description: Learn how to use tools in Agno to build AI agents.
---

**Agents use tools to take actions and interact with external systems**.

Tools are functions that an Agent can run to achieve tasks. For example: searching the web, running SQL, sending an email or calling APIs. You can use any python function as a tool or use a pre-built Agno **toolkit**.

The general syntax is:

```python
from agno.agent import Agent

agent = Agent(
    # Add functions or Toolkits
    tools=[...],
)
```

## Using a Toolkit

Agno provides many pre-built **toolkits** that you can add to your Agents. For example, let's use the DuckDuckGo toolkit to search the web.

<Tip>
  You can find more toolkits in the [Toolkits](/concepts/tools/toolkits) guide.
</Tip>

<Steps>
  <Step title="Create Web Search Agent">
    Create a file `web_search.py`

    ```python web_search.py
    from agno.agent import Agent
    from agno.tools.duckduckgo import DuckDuckGoTools

    agent = Agent(tools=[DuckDuckGoTools()], markdown=True)
    agent.print_response("Whats happening in France?", stream=True)
    ```

  </Step>
  <Step title="Run the agent">
    Install libraries

    ```shell
    pip install openai ddgs agno
    ```

    Run the agent

    ```shell
    python web_search.py
    ```

  </Step>
</Steps>

## Writing your own Tools

For more control, write your own python functions and add them as tools to an Agent. For example, here's how to add a `get_top_hackernews_stories` tool to an Agent.

```python hn_agent.py
import json
import httpx

from agno.agent import Agent

def get_top_hackernews_stories(num_stories: int = 10) -> str:
    """Use this function to get top stories from Hacker News.

    Args:
        num_stories (int): Number of stories to return. Defaults to 10.
    """

    # Fetch top story IDs
    response = httpx.get('https://hacker-news.firebaseio.com/v0/topstories.json')
    story_ids = response.json()

    # Fetch story details
    stories = []
    for story_id in story_ids[:num_stories]:
        story_response = httpx.get(f'https://hacker-news.firebaseio.com/v0/item/{story_id}.json')
        story = story_response.json()
        if "text" in story:
            story.pop("text", None)
        stories.append(story)
    return json.dumps(stories)

agent = Agent(tools=[get_top_hackernews_stories], markdown=True)
agent.print_response("Summarize the top 5 stories on hackernews?", stream=True)
```

Read more about:

- [Available toolkits](/concepts/tools/toolkits)
- [Creating your own tools](/concepts/tools/custom-tools)

### Accessing built-in parameters in tools
You can access agent attributes like `session_state`, `dependencies`, `agent` and `team` in your tools.

<Note>
  To access session data, like `session_state` and `dependencies`, you will use the `run_context` object.
  See the [RunContext schema](/reference/run/run_context) for more information.
</Note>

For example:

```python
from agno.agent import Agent
from agno.run import RunContext

def get_shopping_list(run_context: RunContext) -> str:
    """Get the shopping list."""
    return run_context.session_state["shopping_list"]

agent = Agent(tools=[get_shopping_list], session_state={"shopping_list": ["milk", "bread", "eggs"]}, markdown=True)
agent.print_response("What's on my shopping list?", stream=True)
```

See more in the [Tool Built-in Parameters](/concepts/tools/overview#tool-built-in-parameters) section.

## MCP Tools

Agno supports [Model Context Protocol (MCP)](/concepts/tools/mcp) tools.

The general syntax is:

```python
from agno.agent import Agent
from agno.tools.mcp import MCPTools

async def run_mcp_agent():

    # Initialize the MCP tools
    mcp_tools = MCPTools(command=f"uvx mcp-server-git")

    # Connect to the MCP server
    await mcp_tools.connect()

    agent = Agent(tools=[mcp_tools], markdown=True)
    await agent.aprint_response("What is the license for this project?", stream=True)
    ...
```

<Tip>
  {" "}
  Learn more about MCP tools in the [MCP tools](/concepts/tools/mcp) guide.
</Tip>

## Developer Resources

- View the [Agent schema](/reference/agents/agent)
- View the [Knowledge schema](/reference/knowledge/knowledge)
- View [Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/knowledge/)
